package Wires.diagram.edit.parts;

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Connection;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.PolygonDecoration;
import org.eclipse.draw2d.RotatableDecoration;
import org.eclipse.draw2d.geometry.PointList;
import org.eclipse.gef.EditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionNodeEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITreeBranchEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
import org.eclipse.gmf.runtime.draw2d.ui.figures.PolylineConnectionEx;
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;

/**
 * @generated
 */
public class DecisionNodeTrueBranchEditPart extends ConnectionNodeEditPart
		implements ITreeBranchEditPart {

	/**
	 * @generated
	 */
	public static final int VISUAL_ID = 3002;

	/**
	 * @generated
	 */
	public DecisionNodeTrueBranchEditPart(View view) {
		super(view);
	}

	/**
	 * @generated
	 */
	protected void createDefaultEditPolicies() {
		super.createDefaultEditPolicies();
		installEditPolicy(
				EditPolicyRoles.SEMANTIC_ROLE,
				new Wires.diagram.edit.policies.DecisionNodeTrueBranchItemSemanticEditPolicy());
	}

	/**
	 * @generated
	 */
	protected boolean addFixedChild(EditPart childEditPart) {
		if (childEditPart instanceof Wires.diagram.edit.parts.WrappingLabel29EditPart) {
			((Wires.diagram.edit.parts.WrappingLabel29EditPart) childEditPart)
					.setLabel(getPrimaryShape().getFigureTrueBranchTrueFigure());
			return true;
		}
		return false;
	}

	/**
	 * @generated
	 */
	protected void addChildVisual(EditPart childEditPart, int index) {
		if (addFixedChild(childEditPart)) {
			return;
		}
		super.addChildVisual(childEditPart, -1);
	}

	/**
	 * Creates figure for this edit part.
	 * 
	 * Body of this method does not depend on settings in generation model
	 * so you may safely remove <i>generated</i> tag and modify it.
	 * 
	 * @generated
	 */

	protected Connection createConnectionFigure() {
		return new TrueBranchFigure();
	}

	/**
	 * @generated
	 */
	public TrueBranchFigure getPrimaryShape() {
		return (TrueBranchFigure) getFigure();
	}

	/**
	 * @generated
	 */
	public class TrueBranchFigure extends PolylineConnectionEx {

		/**
		 * @generated
		 */
		private WrappingLabel fFigureTrueBranchTrueFigure;

		/**
		 * @generated
		 */
		public TrueBranchFigure() {
			this.setLineStyle(Graphics.LINE_DASH);
			this.setForegroundColor(THIS_FORE);

			createContents();
			setTargetDecoration(createTargetDecoration());
		}

		/**
		 * @generated
		 */
		private void createContents() {

			fFigureTrueBranchTrueFigure = new WrappingLabel();
			fFigureTrueBranchTrueFigure.setText("<true>");
			fFigureTrueBranchTrueFigure
					.setForegroundColor(FFIGURETRUEBRANCHTRUEFIGURE_FORE);

			this.add(fFigureTrueBranchTrueFigure);

		}

		/**
		 * @generated NOT
		 */
		private RotatableDecoration createTargetDecoration() {
			PolygonDecoration df = new PolygonDecoration();
			df.setFill(true);
			df.setForegroundColor(DF_FORE);
			df.setBackgroundColor(ColorConstants.white);
			PointList pl = new PointList();
			pl.addPoint(getMapMode().DPtoLP(-3), getMapMode().DPtoLP(4));
			pl.addPoint(getMapMode().DPtoLP(-1), getMapMode().DPtoLP(3));
			pl.addPoint(getMapMode().DPtoLP(0), getMapMode().DPtoLP(1));
			pl.addPoint(getMapMode().DPtoLP(0), getMapMode().DPtoLP(-1));
			pl.addPoint(getMapMode().DPtoLP(-1), getMapMode().DPtoLP(-3));
			pl.addPoint(getMapMode().DPtoLP(-3), getMapMode().DPtoLP(-4));
			pl.addPoint(getMapMode().DPtoLP(-5), getMapMode().DPtoLP(-4));
			pl.addPoint(getMapMode().DPtoLP(-7), getMapMode().DPtoLP(-3));
			pl.addPoint(getMapMode().DPtoLP(-8), getMapMode().DPtoLP(-1));
			pl.addPoint(getMapMode().DPtoLP(-8), getMapMode().DPtoLP(1));
			pl.addPoint(getMapMode().DPtoLP(-7), getMapMode().DPtoLP(3));
			pl.addPoint(getMapMode().DPtoLP(-5), getMapMode().DPtoLP(4));
			pl.addPoint(getMapMode().DPtoLP(-3), getMapMode().DPtoLP(4));
			df.setTemplate(pl);
			df.setScale(getMapMode().DPtoLP(1), getMapMode().DPtoLP(1));
			return df;
		}

		/**
		 * @generated
		 */
		public WrappingLabel getFigureTrueBranchTrueFigure() {
			return fFigureTrueBranchTrueFigure;
		}

	}

	/**
	 * @generated
	 */
	static final Color THIS_FORE = new Color(null, 158, 74, 78);

	/**
	 * @generated
	 */
	static final Color FFIGURETRUEBRANCHTRUEFIGURE_FORE = new Color(null, 158,
			74, 78);

	/**
	 * @generated
	 */
	static final Color DF_FORE = new Color(null, 158, 74, 78);

}
